const modulesFiles = require.context('./modules', true, /\.js$/)
// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
let modules = {}
const result = modulesFiles.keys().reduce((preObj, modulePath) => {
  const module = modulesFiles(modulePath)
  // Object.assign(preObj, value)
  // modules = { ...modules, ...preObj }
  // const moduleName = path.replace(/\.\/(\w*?).js$/, '$1')
  Object.keys(module).forEach(key => {
    const item = module[key]
    if (key === 'default') {
      modules = { ...modules, ...item }
    } else {
      modules = { ...modules, [key]: item }
    }
  })
  return modules
}, {})

export default result
